package com.prime.tutorial.moviestore.service.admin;

import com.prime.tutorial.moviestore.dao.GroupsDAO;
import com.prime.tutorial.moviestore.dao.UserDAO;
import com.prime.tutorial.moviestore.domain.Groups;
import com.prime.tutorial.moviestore.domain.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Implementation of {@link AdminService}<br/>
 * Created by IntelliJ IDEA. <br/>
 * Users: me<br/>
 * Date: 22 лют 2010 <br/>
 * Time: 9:33:18<br/>
 * @author iryna.masyuk<br/>
 */
@Service
public class AdminServiceImpl implements AdminService {
    GroupsDAO groupsDAO;
    UserDAO userDAO;

    @Autowired
    public AdminServiceImpl(GroupsDAO groupsDAO,UserDAO userDAO) {
        this.groupsDAO = groupsDAO;
        this.userDAO = userDAO;
    }

    public List<Groups> getAllGroups(){
        return groupsDAO.loadAll();
    };
    public List<Users> getAllUsers(){
        return userDAO.loadAll();
    };
    public Boolean loginExists(String login){
        return !(userDAO.findByLogin(login).isEmpty());
    };
    public List<Groups> findByName(String name){
        return groupsDAO.findByName(name);
    };

    public void createNew(Users users){
        userDAO.persist(users);
    };

    public void deleteUser(Users users){
       userDAO.delete(users);
    };

    public void updateUser(Users users){
        userDAO.update(users);
    };
}
